using System.ComponentModel;
using NUnit.Framework;
using ValidationFramework;

namespace ExampleLibraryCSharp.BusinessBaseClasses
{
	public class NotifyBaseLambdaExample
	{
		#region Example
		public class Person : NotifyBase
		{
			#region Fields

			private string firstName;
			private string lastName;
			private string emailAddress;

			#endregion


			#region Properties

			public string FirstName
			{
				get
				{
					return firstName;
				}
				set
				{
					if (firstName != value)
					{
						firstName = value;
						NotifyPropertyChanged(() => FirstName);
					}
				}
			}


			public string LastName
			{
				get
				{
					return lastName;
				}
				set
				{
					if (lastName != value)
					{
						lastName = value;
						NotifyPropertyChanged(() => LastName);
					}
				}
			}


			public string EmailAddress
			{
				get
				{
					return emailAddress;
				}
				set
				{
					if (emailAddress != value)
					{
						emailAddress = value;
						NotifyPropertyChanged(() => EmailAddress);
					}
				}
			}


			#endregion
		}

		[TestFixture]
		public class ExampleUsage
		{
			private bool firstNameEventFired;

			[Test]
			public void RunEvent()
			{
				var person = new Person();

				// Attach to PropertyChanged so we are notified 
				person.PropertyChanged += person_PropertyChanged;

				// Set FirstName and hence firing the event
				person.FirstName = "John";

				// Since the event has fired the firstNameEventFired flag will be true;
				Assert.IsTrue(firstNameEventFired);
			}


			void person_PropertyChanged(object sender,
			                            PropertyChangedEventArgs e)
			{
				firstNameEventFired = true;
			}


		}
		#endregion
	}
}